package com.fancy.controller.api;

import com.fancy.emums.StatusEnum;
import com.fancy.po.ProductInfo;
import com.fancy.service.ProductInfoService;
import com.fancy.util.ResultUtil;
import com.fancy.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 商品api
 * Created by FancyFong on 7/9/2017.
 */
@RestController
public class ProductInfoApiController {

    @Autowired
    private ProductInfoService productInfoService;


    @GetMapping(value = "/product/list")
    public ResultVO findProductAllList(@RequestParam("productId") String productId) {
        //Integer i =1/0;

        //获取所有上架商品
        List<ProductInfo> productInfos =  productInfoService.findUpAll();

        productInfoService.findOne(productId);

        //提取所有商品id lambda
        List<String> productIdList = productInfos.stream().map(e -> e.getProductId()).collect(Collectors.toList());

        return ResultUtil.success(StatusEnum.SUCCESS,productIdList);

    }

}
